﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;

namespace ChatForum.WCF
{
    public class HostManager
    {
        private static HostManager instance;
        private static object _lock = new object();
        private HostManager() { hostList = new Dictionary<string, ServiceHost>(); }
        public static HostManager Instance
        {
            get
            {
                lock (_lock)
                {
                    if (instance == null)
                        instance = new HostManager();
                }
                return instance;
            }
        }

        private Dictionary<string, ServiceHost> hostList;
        public ServiceHost this[string key]
        {
            get { return hostList[key]; }
            set { hostList[key] = value; }
        }

        public void StartServices()
        {
            foreach (string key in this.hostList.Keys)
            {
                this.hostList[key].Open();
            }
        }

        public void StopServices()
        {
            foreach (string key in this.hostList.Keys)
            {
                this.hostList[key].Close();
            }
        }
    }
}
